package com.example.mvc.controller;

import com.example.mvc.bean.History;
import com.example.mvc.bean.User;
import com.example.mvc.service.BookBorrowService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;

//用户借阅信息列表（处于借的状态）
@WebServlet("/borrowListByUserServlet")
public class BorrowListByUserServlet  extends HttpServlet {
    BookBorrowService bookBorrowService= new BookBorrowService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        List<History> borrowBookListByUser = bookBorrowService.getBorrowBookListByUser(user);
        session.setAttribute("borrowBookListByUser",borrowBookListByUser);
        String contextPath = req.getContextPath();
        resp.sendRedirect(contextPath+"/user_borrow.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
